import type { BADAAircraftTypeModel } from './types'

export const badaModels: Record<string, BADAAircraftTypeModel> = {}
export const badaCodeList: string[] = []

export async function loadBadaData() {
  const resp = await fetch('./bada-model.json')
  const lst = (await resp.json()) as BADAAircraftTypeModel[]
  for (const e of lst) {
    badaModels[e.id] = e
    badaCodeList.push(e.id)
  }
  badaCodeList.sort()
}

export function getBADAModel(id: string): BADAAircraftTypeModel | null {
  return badaModels[id] || null
}
